//
//  BaseNavController.swift
//  NSinaWeibo
//
//  Created by LoliQueen on 16/2/24.
//  Copyright © 2016年 LoliQueen. All rights reserved.
//

import UIKit

//遵守手势方法，自定义了
class BaseNavController: UINavigationController,UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()

        //一旦实现返回按钮的自定义，返回手势和点击返回事件就失效了，需要手动添加
        self.interactivePopGestureRecognizer?.delegate = self
    }
///只要有控制器跳转，就会调用这个方法
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        print("哈哈哈")
        
        //获取子视图控制器的数量
        let count = childViewControllers.count
        if count != 0 {
           viewController.hidesBottomBarWhenPushed = true
            
//            //自定义返回按钮
            let btn :UIButton = UIButton(backImageName: nil, title: "返回", textColor: themeColor, imageName: "navigationbar_back_withtext", fontSize: 14)
            ///自定义按钮就要自定义对应的点击事件
            btn.addTarget(self, action: "back", forControlEvents: .TouchUpInside)
            
           viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        }
//        父类方法放在判断下面，不满足条件时 显示tabelBar
        super.pushViewController(viewController, animated: animated)
        
    }
    
    @objc private func back(){
        self.popViewControllerAnimated(true)
    }
    
    ///自定义手势方法
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        ///不是首页就 设置返回手势
        return childViewControllers.count > 1
    }

}
